package com.qf.pojo;

import java.util.HashMap;

/**
 * 封装一个返回结果实体类
 * @author fy
 * @version V1.0
 * @Project workspace
 * @Package com.qf.pojo
 * @Description:
 * @Date 2022/6/17 15:31
 */
/**
 * 封装一个Map的工具类，处理前端响应
 *原来：
 * Map<String , O bject> map = new HashMap<>();
 *         map.put("code",0);
 *          map.put("msg","成功");
 *         return  map;
 * JsonObject
 *
 * 通过工具类：
 *         return  Result.ok("成功");
 */
public class Result extends HashMap {

    //响应消息
    private String msg;

    //响应状态码
    private int code;

    //无参构造
    public Result(){}
    //有参构造
    public Result(int code,String msg){
        this.code=code;
        this.msg=msg;
    }
    //有参构造
    public Result(int code){
        this.code=code;
    }
    //有参构造
    public Result(String msg){
        this.msg=msg;
    }


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
    //返回成功的状态码
    public  static Result ok(){
        return new Result(0);
    }
    //返回成功的状态信息
    public  static Result ok(String msg){
        return new Result(0,msg);
    }

    //返回失败的状态码
    public  static Result error(){
        return new Result(1);
    }
    //返回失败的状态信息
    public  static Result error(String msg){
        return new Result(1,msg);
    }

    public Result put(String key, Object value){
        super.put(key,value);

        return this;
    }

   
}
